﻿using UnityEngine;

public class UIListItem : AbstractButton {
	// === Public =====================================================================================================
	public UIListItem(ButtonModel buttonModel, Texture image, string text) {
		Init(buttonModel, image, text);
		_buttonModel = buttonModel;
	}

	public UIListItem(ButtonElement buttonElement, Texture image, string text) {
		Init(buttonElement, image, text);
		_buttonElement = buttonElement;
	}

	public UIListItemTexture GetUITexture() { return _texture; }
	public UIListItemLabel GetUILabel() { return _label; }

	public bool IsButtonModel() { return _buttonModel != null; }
	public ButtonModel GetButtonModel() { return _buttonModel; }

	public bool IsButtonElement() { return _buttonElement != null; }
	public ButtonElement GetButtonElement() { return _buttonElement; }

	// === Private ====================================================================================================
	private UIListItemTexture _texture;
	private UIListItemLabel _label;
	private readonly ButtonModel _buttonModel;
	private readonly ButtonElement _buttonElement;

	private void Init(IButtonAction action, Texture image, string text) {
		SetName(GetType().ToString());
		SetLocation(0, 0);
		SetSize(80, 100);
		ButtonAction = action;
		UpdateStyle();

		_texture = new UIListItemTexture(image, ScaleMode.StretchToFill);
		_label = new UIListItemLabel(text);
	}
}